package cn.zch.util.jsonutil;
//解析复杂json 处理方法
// 示例见复杂json串.json 文件
//使用jackson就可以了。
//我用的jackson-core-asl-1.9.13.jar；jackson-mapper-asl-1.9.13.jar。
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;

import java.util.List;
public class Hello {
	private static ObjectMapper mapper = new ObjectMapper();
	public static void main(String[] args) throws Exception {
		// json strings
		String json = "[{\"id\":1,\"count\":25,\"isEnd\":0,\"children\":[{\"id\":57,\"count\":3,\"isEnd\":0,\"parentInditarator\":1,\"children\":[{\"id\":150,\"count\":1,\"isEnd\":1,\"parentInditarator\":57,\"topInditarator\":1,\"code\":\"cyxxs57\",\"targetName\":\"查阅信息数\",\"targetCategory\":3,\"size\":0},{\"id\":149,\"count\":1,\"isEnd\":1,\"parentInditarator\":57,\"topInditarator\":1,\"code\":\"jdrc57\",\"targetName\":\"接待人次\",\"targetCategory\":3,\"size\":0},{\"id\":148,\"count\":1,\"isEnd\":1,\"parentInditarator\":57,\"topInditarator\":1,\"code\":\"cyds57\",\"targetName\":\"查阅点数\",\"targetCategory\":3,\"size\":0}],\"topInditarator\":1,\"code\":\"tsg\",\"targetName\":\"图书馆\",\"targetCategory\":2,\"size\":0},{\"id\":56,\"count\":3,\"isEnd\":0,\"parentInditarator\":1,\"children\":[{\"id\":147,\"count\":1,\"isEnd\":1,\"parentInditarator\":56,\"topInditarator\":1,\"code\":\"cyxxs56\",\"targetName\":\"查阅信息数\",\"targetCategory\":3,\"size\":0},{\"id\":146,\"count\":1,\"isEnd\":1,\"parentInditarator\":56,\"topInditarator\":1,\"code\":\"jdrc56\",\"targetName\":\"接待人次\",\"targetCategory\":3,\"size\":0},{\"id\":145,\"count\":1,\"isEnd\":1,\"parentInditarator\":56,\"topInditarator\":1,\"code\":\"cyds56\",\"targetName\":\"查阅点数\",\"targetCategory\":3,\"size\":0}],\"topInditarator\":1,\"code\":\"dag\",\"targetName\":\"档案馆\",\"targetCategory\":2,\"size\":0},{\"id\":55,\"count\":3,\"isEnd\":0,\"parentInditarator\":1,\"children\":[{\"id\":144,\"count\":1,\"isEnd\":1,\"parentInditarator\":55,\"topInditarator\":1,\"code\":\"cyxxs55\",\"targetName\":\"查阅信息数\",\"targetCategory\":3,\"size\":0},{\"id\":143,\"count\":1,\"isEnd\":1,\"parentInditarator\":55,\"topInditarator\":1,\"code\":\"jdrc55\",\"targetName\":\"接待人次\",\"targetCategory\":3,\"size\":0},{\"id\":142,\"count\":1,\"isEnd\":1,\"parentInditarator\":55,\"topInditarator\":1,\"code\":\"cyds55\",\"targetName\":\"查阅点数\",\"targetCategory\":3,\"size\":0}],\"topInditarator\":1,\"code\":\"zwfwzx\",\"targetName\":\"政务服务中心\",\"targetCategory\":2,\"size\":0},{\"id\":54,\"count\":1,\"isEnd\":1,\"parentInditarator\":1,\"topInditarator\":1,\"code\":\"qttjzdgkzfxxts\",\"targetName\":\"其他途径主动公开政府信息条数\",\"targetCategory\":2,\"size\":0},{\"id\":53,\"count\":3,\"isEnd\":0,\"parentInditarator\":1,\"children\":[{\"id\":141,\"count\":1,\"isEnd\":1,\"parentInditarator\":53,\"topInditarator\":1,\"code\":\"gkzfxxts53\",\"targetName\":\"公开政府信息条数\",\"targetCategory\":3,\"size\":0},{\"id\":140,\"count\":1,\"isEnd\":1,\"parentInditarator\":53,\"topInditarator\":1,\"code\":\"zfgbckqs\",\"targetName\":\"政府公报出刊期数\",\"targetCategory\":3,\"size\":0},{\"id\":139,\"count\":1,\"isEnd\":1,\"parentInditarator\":53,\"topInditarator\":1,\"code\":\"byzfgbs\",\"targetName\":\"办有政府公报数\",\"targetCategory\":3,\"size\":0}],\"topInditarator\":1,\"code\":\"zfgbgkqk\",\"targetName\":\"政府公报公开情况\",\"targetCategory\":2,\"size\":0},{\"id\":52,\"count\":3,\"isEnd\":0,\"parentInditarator\":1,\"children\":[{\"id\":138,\"count\":1,\"isEnd\":1,\"parentInditarator\":52,\"topInditarator\":1,\"code\":\"zjxxgksj52\",\"targetName\":\"最近信息公开时间\",\"targetCategory\":3,\"size\":0},{\"id\":137,\"count\":1,\"isEnd\":1,\"parentInditarator\":52,\"topInditarator\":1,\"code\":\"gkzfxxts52\",\"targetName\":\"公开政府信息条数\",\"targetCategory\":3,\"size\":0},{\"id\":136,\"count\":1,\"isEnd\":1,\"parentInditarator\":52,\"topInditarator\":1,\"code\":\"ktzwwxgs\",\"targetName\":\"开通政务微信个数\",\"targetCategory\":3,\"size\":0}],\"topInditarator\":1,\"code\":\"zfwxgkqk\",\"targetName\":\"政务微信公开情况\",\"targetCategory\":2,\"size\":0},{\"id\":51,\"count\":3,\"isEnd\":0,\"parentInditarator\":1,\"children\":[{\"id\":135,\"count\":1,\"isEnd\":1,\"parentInditarator\":51,\"topInditarator\":1,\"code\":\"zjgksj51\",\"targetName\":\"最近信息公开时间\",\"targetCategory\":3,\"size\":0},{\"id\":134,\"count\":1,\"isEnd\":1,\"parentInditarator\":51,\"topInditarator\":1,\"code\":\"gkzfxxts51\",\"targetName\":\"公开政府信息条数\",\"targetCategory\":3,\"size\":0},{\"id\":133,\"count\":1,\"isEnd\":1,\"parentInditarator\":51,\"topInditarator\":1,\"code\":\"ktzwwbgs\",\"targetName\":\"开通政务微博个数\",\"targetCategory\":3,\"size\":0}],\"topInditarator\":1,\"code\":\"zfwbgkqk\",\"targetName\":\"政务微博公开情况\",\"targetCategory\":2,\"size\":0},{\"id\":50,\"count\":5,\"isEnd\":0,\"parentInditarator\":1,\"children\":[{\"id\":111,\"count\":2,\"isEnd\":0,\"parentInditarator\":50,\"children\":[{\"id\":113,\"count\":1,\"isEnd\":1,\"parentInditarator\":111,\"topInditarator\":1,\"code\":\"zjxxgksj\",\"targetName\":\"最近信息公开时间\",\"targetCategory\":4,\"size\":0},{\"id\":112,\"count\":1,\"isEnd\":1,\"parentInditarator\":111,\"topInditarator\":1,\"code\":\"zfxxgkmlgks\",\"targetName\":\"政府信息公开目录公开数\",\"targetCategory\":4,\"size\":0}],\"topInditarator\":1,\"code\":\"zfxxgkmlgkqk\",\"targetName\":\"政府信息公开目录公开情况\",\"targetCategory\":3,\"size\":0},{\"id\":110,\"count\":1,\"isEnd\":1,\"parentInditarator\":50,\"topInditarator\":1,\"code\":\"zfwzgks\",\"targetName\":\"政府网站公开数\",\"targetCategory\":3,\"size\":0},{\"id\":130,\"count\":2,\"isEnd\":0,\"parentInditarator\":50,\"children\":[{\"id\":132,\"count\":1,\"isEnd\":1,\"parentInditarator\":130,\"topInditarator\":1,\"code\":\"zjgksj130\",\"targetName\":\"最近信息公开时间\",\"targetCategory\":4,\"size\":0},{\"id\":131,\"count\":1,\"isEnd\":1,\"parentInditarator\":130,\"topInditarator\":1,\"code\":\"wztgmlwgks\",\"targetName\":\"网站通过目录外公开数\",\"targetCategory\":4,\"size\":0}],\"topInditarator\":1,\"code\":\"wztgmlwgkqk\",\"targetName\":\"网站通过目录外公开情况\",\"targetCategory\":3,\"size\":0}],\"topInditarator\":1,\"code\":\"zfwzgkqk\",\"targetName\":\"政府网站公开情况\",\"targetCategory\":2,\"size\":0},{\"id\":49,\"count\":1,\"isEnd\":1,\"parentInditarator\":1,\"topInditarator\":1,\"code\":\"zdgkzfxxzts\",\"targetName\":\"主动公开政府信息总条数\",\"targetCategory\":2,\"size\":0}],\"code\":\"zdgk\",\"targetName\":\"主动公开\",\"targetCategory\":1,\"size\":0}]";
		// json to object list
		// the TypeReference is abstract object
		List<JsonModel> list = mapper.readValue(json, new TypeReference<List<JsonModel>>() {});
		System.out.println(list.get(0).children.size());
		// print the list
		print(list);
	}
	private static void print(List<JsonModel> models) {
		if (models == null || models.size() == 0) {
			return;
		}
		for (JsonModel model : models) {
			model.print();
			print(model.children);
		}
	}
}


